using UnityEngine;

namespace BasicScript.Component
{
	public class ButtonObject : MonoBehaviour
	{
		private enum Anim
		{
			Static = 0,
			ZoomIn = 1,
			ZoomOut = 2
		}

		private Anim anim;

		public float zoomInScaleX;

		public float zoomInScaleY;

		public float zoomOutScaleX;

		public float zoomOutScaleY;

		private float curScaleX;

		private float curScaleY;

		private float timer;

		public void InitParams(float zoomInScaleX, float zoomInScaleY, float zoomOutScaleX, float zoomOutScaleY)
		{
			this.zoomInScaleX = zoomInScaleX;
			this.zoomInScaleY = zoomInScaleY;
			this.zoomOutScaleX = zoomOutScaleX;
			this.zoomOutScaleY = zoomOutScaleY;
		}

		public void LateUpdate()
		{
			if (anim == Anim.Static)
			{
				return;
			}
			if (anim == Anim.ZoomIn)
			{
				timer += Time.deltaTime * 6f;
				curScaleX = Mathf.Lerp(zoomOutScaleX, zoomInScaleX, timer);
				curScaleY = Mathf.Lerp(zoomOutScaleY, zoomInScaleY, timer);
				if (curScaleX >= zoomInScaleX && curScaleY >= zoomInScaleY)
				{
					SetScale(zoomInScaleX, zoomInScaleY);
					anim = Anim.Static;
				}
				else
				{
					SetScale(curScaleX, curScaleY);
				}
			}
			else if (anim == Anim.ZoomOut)
			{
				timer -= Time.deltaTime * 6f;
				curScaleX = Mathf.Lerp(zoomOutScaleX, zoomInScaleX, timer);
				curScaleY = Mathf.Lerp(zoomOutScaleY, zoomInScaleY, timer);
				if (curScaleX <= zoomOutScaleX && curScaleY <= zoomOutScaleY)
				{
					SetScale(zoomOutScaleX, zoomOutScaleY);
					anim = Anim.Static;
				}
				else
				{
					SetScale(curScaleX, curScaleY);
				}
			}
		}

		public void ZoomIn()
		{
			if (!(timer >= 1f))
			{
				anim = Anim.ZoomIn;
			}
		}

		public void ZoomOut()
		{
			if (!(timer <= 0f))
			{
				anim = Anim.ZoomOut;
			}
		}

		private void SetScale(float x, float y)
		{
			base.transform.localScale = new Vector3(x, y, 1f);
		}
	}
}
